#include "dailytimertest.h"
#include <QDateTime>

DailyTimerTest::DailyTimerTest()
{
}

bool DailyTimerTest::rescheduleTimer()
{
	QDateTime* dt = new QDateTime(QDateTime::currentDateTime());
	*dt = dt->addSecs(-5*60);
	int hour = dt->time().hour();
	int minute = dt->time().minute();

	QDateTime* expected = new QDateTime(*dt);
	expected->setTime(QTime(hour, minute, 0, 0));
	*expected = expected->addSecs(10*60);

	QDailyTimer* timer = new QDailyTimer(hour, minute);
	timer->start();
	timer->reschedule(expected->time().hour(), expected->time().minute());

	QDateTime* calculated = timer->nextSchedule();

	if (*calculated == *expected)
		return true;
	else
		return false;
}

bool DailyTimerTest::paramTimeIsInThePast()
{
    QDateTime* dt = new QDateTime(QDateTime::currentDateTime());
    *dt = dt->addSecs(-5*60);
    int hour = dt->time().hour();
    int minute = dt->time().minute();

    QDateTime* expected = new QDateTime(*dt);
    expected->setTime(QTime(hour, minute, 0, 0));
    *expected = expected->addDays(1);

    QDailyTimer* timer = new QDailyTimer(hour, minute);
    timer->start();

    QDateTime* calculated = timer->nextSchedule();

    if (*calculated == *expected)
        return true;
    else
        return false;
}

bool DailyTimerTest::paramTimeIsInTheFuture()
{
    QDateTime* dt = new QDateTime(QDateTime::currentDateTime());
    *dt = dt->addSecs(5*60);
    int hour = dt->time().hour();
    int minute = dt->time().minute();

    QDateTime* expected = new QDateTime(*dt);
    expected->setTime(QTime(hour, minute, 0, 0));

    QDailyTimer* timer = new QDailyTimer(hour, minute);
    timer->start();

    QDateTime* calculated = timer->nextSchedule();

    if (*calculated == *expected)
        return true;
    else
        return false;
}
